package viettravel.guiandevent.place;

import java.util.ArrayList;

import viettravel.DAO.Comment;
import viettravel.common.Constants;
import viettravel.guiandevent.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListCommentAdapter extends BaseAdapter {

	private ArrayList<Comment> mComment;
	private Context mContext;
	
	public ListCommentAdapter(ArrayList<Comment> _comment, Context _context){
		mComment = new ArrayList<Comment>();
		mComment.addAll(_comment);
		mContext = _context;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mComment.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mComment.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View _view, ViewGroup _viewGroup) {
		// TODO Auto-generated method stub
		View view = _view;
		if (view == null){
			LayoutInflater layoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = layoutInflater.inflate(R.layout.row_comment, null);
        }
		//ImageView commentImageSender = (ImageView)view.findViewById(R.id.commentImageSender);
		TextView commentSender = (TextView)view.findViewById(R.id.commentSender);
		ImageView commentImageUpload = (ImageView)view.findViewById(R.id.commentImageUpload);
		TextView commentContent = (TextView)view.findViewById(R.id.commentContent);
		
		commentSender.setTypeface(Constants.TYPEFACE_CAVIAR);
		//commentSender.
		
		Comment comment = mComment.get(position);
		commentSender.setText(comment.getCommentSender() + " said that:");
		if(comment.getCommentImage()!= null){
			Log.v(Constants.TAG, "listcomment come here");
			Log.v(Constants.TAG, comment.getCommentImage().toString());
			commentImageUpload.setBackgroundDrawable(comment.getCommentImage());
		}
		else{
			Log.v(Constants.TAG, "listcomment or come here");
			commentImageUpload.setVisibility(View.GONE);
		}
		commentContent.setText(comment.getCommentContent());                           
		return view;
	}
}
